﻿using System;
using System.Web.UI;
using Spring.Web.UI;
using System.Reflection;

namespace SpringSeries.Core.ValidationWebForm{
    public partial class PersonEdit : Spring.Web.UI.Page{
        private Person _person;
        private Spring.Validation.IValidator _personValidator;

        public Spring.Validation.IValidator PersonValidator{
            set { _personValidator = value; }
        }

        protected void btnSave_Click(object sender, EventArgs e){
            _person = new Person(1);
            _person.FirstName = txtFirstname.Text;
            _person.LastName = txtLastName.Text;
            _person.DateOfBirth = clDateOfBirth.SelectedDate;
            _person.AddressInfo.Address = txtAddress.Text;
            _person.AddressInfo.City = txtCity.Text;
            _person.AddressInfo.PostalCode = txtPostalCode.Text;

            if (Validate(_person, _personValidator))
            {
                Response.Redirect("PersonValid.aspx");
            }            
        }
    }
}
